package net.dataforte.tooonebee.system;

import static net.dataforte.tooonebee.Menu.menu;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Set;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import net.dataforte.tooonebee.Menu;
import net.dataforte.tooonebee.ServiceIntrospector;

public class SystemIntrospector extends ServiceIntrospector {
	
	@Override
	public Set<Menu> getMenuEntries() {
		Set<Menu> entries = super.getMenuEntries();
		entries.add(
			menu("System", this.getRequestPath(), 
				menu("Filesystems", "filesystems"),
				menu("Network", "network"),
				menu("Processes", "processes")
			)
		);
		return entries;
	}

	@Override
	public String getRequestPath() {
		return "system";
	}

	@Override
	public void handleRequest(HttpServlet servlet, HttpServletRequest req, HttpServletResponse res) throws Exception {
		// TODO Auto-generated method stub

	}
	
	public void networkIntrospector(Node node) throws SocketException, DOMException {
		Document doc = node.getOwnerDocument();
		Element networkNode = doc.createElement("<network>");
		node.appendChild(networkNode);
		for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
			NetworkInterface nic = en.nextElement();
			Element interfaceNode = doc.createElement("<interface>");
			node.appendChild(interfaceNode);
		}
		
	}

}
